<?php

class CC_Form_ProviderDropdown extends Zend_Form_Element_Select
{
    /** @var Doctrine\ORM\EntityManager */
    protected $_em;
    
    public function __construct($spec, Doctrine\ORM\EntityManager $em, $options = null)
    {
        $this->_em = $em;
        
        parent::__construct($spec, $options);
    }
    
    public function init()
    {
        $dql = $this->_em->createQuery('SELECT partial p.{id,name} FROM CC\Entity\Provider p');
        $providers = $dql->getResult();
        
        $this->addMultiOption('', 'Please select one...');
        
        foreach($providers as $provider)
            $this->addMultiOption($provider->getId(), $provider->getName());
    }
}